<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jstl/fmt_rt" %>
<%@ taglib prefix="ssm" uri="http://ssm.elangzhi.com/jsp/tag/functions" %>
<%@taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%--
Created by GaoXiang
Date: 2017-03-28 09:07:57 星期二
Version: 1.0
小区列表
--%>

<!DOCTYPE html>
<!--[if IE 8]> <html lang="zh" class="ie8 no-js"> <![endif]-->
<!--[if IE 9]> <html lang="zh" class="ie9 no-js"> <![endif]-->
<!--[if !IE]><!-->
<html lang="zh">
<!--<![endif]-->
<!-- BEGIN HEAD -->
<head>
    <meta charset="utf-8"/>
    <title>物业管理员列表 - 后台服务中心</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1" name="viewport"/>
    <meta content="小区管理员列表" name="description"/>
    <meta content="GaoXiang" name="author"/>
    <jsp:include page="../body/link-page.jsp"/>
</head>
<!-- END HEAD -->
<body class="page-content-white  fade-in-up">

<!-- BEGIN CONTAINER -->
<div class="page-container">
    <!-- BEGIN PAGE TABLE-->
    <div class="portlet light">
        <div class="col-md-2">
            <div class="btn-group">
                <a href="javascript:void(0);" class="btn green " onclick="addResAdminModule()">
                    添加 <i class="fa fa-plus"></i>
                </a>
            </div>
        </div>

        <div class="portlet-body table-responsive">
            <input type="hidden" name="estateId" id="estateId" value="${estateId}">
            <div class="table-scrollable">
                <table data-visible-pages="10" class="table table-bordered table-hover" id="table">
                    <thead>
                    <tr>
                        <th>物业名称</th>
                        <th>用户名</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                   <c:forEach var="item" items="${accountList}" varStatus="status">
                        <tr>
                            <td>${item.estate.name}</td>
                            <td>${item.userName}</td>
                            <td>
                                <c:if test="${item.status=='1'}">正常</c:if>
                                <c:if test="${item.status=='-1'}">禁用</c:if>
                            </td>
                            <td>
                                <div class="btn-group btn-group-xs btn-group-solid">
                                    <c:choose>
                                        <c:when test="${item.status < 1}">
                                            <button data-id="${item.id}" class="btn btn-success allowLogin">恢复登录</button>
                                        </c:when>
                                        <c:otherwise>
                                            <button data-id="${item.id}" class="btn btn-primary disableLogin ">禁止登录</button>
                                        </c:otherwise>
                                    </c:choose>
                                        <button  id="${item.id}"  class="btn btn-danger" onclick="deleteResAdminModule(this.id)" > 删除</button>
                                </div>
                            </td>

                        </tr>
                    </c:forEach>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
    <!-- END PAGE TABLE-->
</div>
<!-- END CONTAINER -->
<jsp:include page="../body/javascript-page.jsp"/>
<!-- BEGIN PAGE JAVASCRIPT-->
<script>

    $(function () {
        /*允许登录（设置status为1）*/
        $(".allowLogin").click(function () {
            try {
                var id = $(this).data("id");
            } catch (e) {
                layer.msg("执行失败！请在删除标签上增加 data-id 列存放数据id！", {icon: 2,time:1000});
            }
            allowAccount(id);
        });
        /*禁止登录（设置status为0）*/
        $(".disableLogin").click(function () {
            try {
                var id = $(this).data("id");
            } catch (e) {
                layer.msg("执行失败！请在删除标签上增加 data-id 列存放数据id！", {icon: 2,time:1000});
            }
            disableAccount(id);
        });


    })


    /**
     * 允许登录
     * */
    function allowAccount(id){
        layer.confirm("确定允许此账号登录么？",function(){
            tools.post("/account/recoverAccount",{id:id},function(data){
                if (data.success) {
                    layer.msg("操作成功！", {icon: 1,time:1000},function(){
                        // toPage(null);
                        //这里单独绑定了按钮事件 必须刷新
                        window.location.reload();
                    });
                }else{
                    layer.msg("操作失败！错误代号："+data.code, {icon: 2,time:1000});
                }
            });
        })
    }

    /**
     * 禁用登录
     * */
    function disableAccount(id){
        layer.confirm("确定禁用此账号登录么？",function(){
            tools.post("/account/forbiddenAccount",{id:id},function(data){
                console.info(data);
                if (data.success) {
                    layer.msg("操作成功！", {icon: 1,time:1000},function(){
                         //toPage(null);
                        //这里单独绑定了按钮事件 必须刷新
                        window.location.reload();
                    });
                }else{
                    layer.msg("操作失败！错误代号："+data.code, {icon: 2,time:1000});
                }
            });
        })
    }



    /**
     * 添加物业管理员信息
     */
    function addResAdminModule() {
        var estateId = $("#estateId").val();
        $.post("/estate/addEstate", {"estateId":estateId}, function(html){
            window.layer_addEstate = layer.open({
                id:"addEsate",
                type: 1,
                title:"添加物业管理员",
                area:['610px','270px'],
                resize:false,
                content: html,
                anim:1,
                shadeClose:false,
                cancel: function(){}
            });
        });

    }

   function deleteResAdminModule(id) {
       layer.confirm("确定要删除吗？",function() {
           tools.post("/estate/deleteEstate", {"id":id}, function (data) {
               if(data.success){
                   layer.msg('删除成功！', {icon: 1,time:1000},function(){
                       location.reload();
                   });
               }else{
                   tools.errorTip(data.code,data.msg);
               }
           });
       });

   }

</script>
<!-- END PAGE JAVASCRIPT-->
</body>
</html>
